package com.xgz.processor.beanpost;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * Bean 的后置增强，是可以修改Bean的类型的
 * 这个增强是对每一个Bean都要执行
 * @author xgz
 */
@Component
public class MyBeanPostProcessor implements BeanPostProcessor {

	public MyBeanPostProcessor() {
		System.out.println("MyBeanPostProcessor 构造器执行...");
	}

	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		System.out.println("Bean后置处理：BeforeInitialization...开始");
		System.out.println(beanName);
		System.out.println("Bean后置处理：BeforeInitialization...结束");
		return bean;
	}

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		System.out.println("Bean后置处理：AfterInitialization...开始");
		System.out.println(beanName);
		System.out.println(bean);
		System.out.println("Bean后置处理：AfterInitialization ...结束");
		return bean;
	}
}
